package com.anxin.registerManagement.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 叶前呈
 * @date 2022/2/7 14:21
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private static final Logger logger = LoggerFactory.getLogger(MyMetaObjectHandler.class);

    @Override
    public void insertFill(MetaObject metaObject) {
        // FIXME:（个人认为）这里应该是处理公共属性，而不是每个类里的插入默认值都设置
        logger.info("自动填充插入数据：{}", new Date());
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        logger.info("自动填充修改数据：{}", new Date());
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
